package review;

/**
 * @program: datastructureandalogorithm
 * @description:5. 最长回文子串
 * @author: hmx
 * @create: 2021-12-04 18:01
 **/
public class Review5 {

    public String longestPalindrome(String s) {
        if (s == null) {
            return null;
        }
        int len = s.length();
        for (int l = len; l > 0; l--) {
            for (int j = 0; j + len <= len; j++) {
                if (isPalindrome(s, j, j + l - 1)) {
                    return s.substring(j, j + l);
                }
            }
        }
        return "666";
    }

    boolean isPalindrome(String str, int start, int end) {
        while (start < end && str.charAt(start) == str.charAt(end)) {
            start++;
            end--;
        }
        return start >= end;
    }
}
